package com.zhangxu.junior.service.impl;

import com.zhangxu.junior.domain.Course;
import com.zhangxu.junior.domain.StudentCourse;
import com.zhangxu.junior.mapper.CourseMapper;
import com.zhangxu.junior.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author zhang xu
 * @Date 2022/6/21 15:32
 * @PackageName:com.zhangxu.junior.service.impl
 * @ClassName: CourseaService
 * @Description: TODO
 * @Version 1.0
 */
@Service
public class CourseaService implements ICourseService {

    @Autowired
    CourseMapper courseMapper;

    @Autowired
    StudentCourseServiceImpl studentCourseService;

    @Override
    public List<Course> sleectCourseList(Course course) {
        return courseMapper.sleectCourseList(course);
    }

    @Override
    public List<Course> selectCourseByIds(List<Long> ids) {
        return courseMapper.selectCourseByIds(ids);
    }

    @Override
    public boolean insertCourse(Course course) {
        if(courseMapper.insertCourse(course) > 0 ){
            return true;
        }
        return false;
    }

    @Override
    @Transactional
    public Map<String,String> delteCourse(Long id) {

        Map<String,String> result = new HashMap<>();


            StudentCourse studentCourse = new StudentCourse();
            studentCourse.setCourseId(id);
            if(studentCourseService.selectCourseBystudent(studentCourse).size()>0){
                result.put("提示","此课程有学生选择！");
            }else {
                courseMapper.delteCourse(id);
                result.put("提示","课程删除成功!");
            }

            return result;

    }


}
